define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 'modalSearch'],
function($, validate) {
  return {
    
    init: function() {
      this.initForm();
    },
    
    initForm: function() {

      $(document).find('form').bt_validate();

        $('.koala-search').koalaSearch({
            url: window.__CTX__.root + "/example-koala-search",
            org: 'company',
            queryName: 'code',
            valueName: 'koalaId',
            value: ["id"],
            display: ["code", "name"]
        });
        
        $('.koala-search').on("koala.search.value.changed", function(e){
          console.log("123");
        })
        
        $('[data-target="#modal-search-example"]').modalsearch({
          url: function() {
            var url = window.__CTX__.root + "/example-koala-modal-search?" + 
                      $(".koala-search").attr("name") + "=" + $(".koala-search").val() +
                      "&" + $(".company").attr("name") + "=" + $(".company").val();
            return url;
          }
        });

//      .on('open.koala.search.modal', function(event) {
//        
//        event.preventDefault();
//        /* Act on the event */
//
//        var $this = $(event.currentTarget);
//        var id = $this.attr('data-target').slice(1);
//
//
//        $.get(url, function (data) {
//          $('<div class="modal fade" id="' + id + '" role="dialog" aria-hidden="true">' + data + '</div>').modal().on('hidden.bs.modal', function (e) {
//            return $(e.currentTarget).remove();
//          }).on('shown.bs.modal', function () {
//            return $this.trigger('shown.modal');
//          });
//        });
//
//      });

      // $('.koala-search').koalaSearch.beforeSearch(function(){
      //   // 校验
      //   console.log("myself before search");
      // })
      
      $('select[name="select"]').select2({
        theme: "classic",
        placeholder : '请选择',
        minimumResultsForSearch : -1,
        allowClear : true,
      });
    }
  }
})